package com.xmy.cultivate.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.cultivate.entity.Grade;
import com.xmy.cultivate.entity.StudentGrade;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xmy.cultivate.entity.views.RenewClassRecord;
import com.xmy.cultivate.entity.views.ResStudentGrade;
import com.xmy.cultivate.entity.views.ShiftList;
import com.xmy.cultivate.respons.ResStudentGradeData;
import com.xmy.cultivate.util.Result;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.springframework.scheduling.annotation.Async;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 学生所在班级与课程 服务类
 * </p>
 *
 * @author min
 * @since 2022-08-09
 */
public interface IStudentGradeService extends IService<StudentGrade> {

    public abstract IPage<ShiftList> findAll(IPage<?> page, Wrapper wrapper);

    public abstract Result divideClasses(Long orderDetailId, Long gradeId);

    public abstract Result melodyClass(StudentGrade studentGrade);

    Long addData(Long orderDetailId, Long schoolId, Long studentId, Long gradeId, Long courseId, Long subjectsId, Integer yearPart, Integer quarterNum, Integer surplusCourseNum, Integer yearClassId, Integer lessonType, Long classTypeIdNew, Integer lackType);

    boolean notDataAndAddData(Long orderDetailId, Long schoolId, Long studentId, Long courseId, Long subjectsId, Integer yearPart, Integer quarterNum, Integer surplusCourseNum, Integer yearClassId, Integer lessonType);

    public abstract String studentAtGradeState(Long gradeId, Long studentId, Integer reType);

    public abstract String getCourseStatus(Long gradeId, Long studentId, Integer reType);

    public abstract String studentAtGradeStateForOrderDetailId(Long orderDetailId, Long studentId, Integer reType);

    public abstract boolean finishCourse(StudentGrade studentGrade);

    boolean studentFixed(StudentGrade studentGrade);

    boolean studentFixedCancel(StudentGrade studentGrade);

    public abstract boolean stopGrade(StudentGrade studentGrade);

    public abstract boolean stopGradeId(String gradeId);

    public abstract boolean courseStatusChange(StudentGrade studentGrade);

    public abstract boolean agrainGrade(StudentGrade studentGrade);

    public abstract boolean finishCourseForOrder(StudentGrade studentGrade);

    public abstract boolean stopGradeForOrder(StudentGrade studentGrade);

    public abstract boolean agrainGradeForOrder(StudentGrade studentGrade);

    boolean agrainBatchGradeForOrder(StudentGrade studentGrade);

    public abstract List<StudentGrade> getlist(Long gradeId);

    public abstract Integer getGradeStudyCount(Long gradeId);

    public abstract Integer getStudentGradeUseCount(Long schoolId, Long studentId, Long subjectsId);

    public abstract Long getStudentCount(QueryWrapper queryWrapper);

    /**
     * 获取学生所在班级的，最后一条信息
     *
     * @param schoolId
     * @param studentId
     * @param subjectsId
     * @param yearPart
     * @param quaterNum
     * @return
     */
    public abstract StudentGrade getLastStudentGradeForOrderDetailId(Long schoolId, Long studentId, Long subjectsId, Integer yearPart, Integer quaterNum, Integer lessonType);

    public abstract Long getStudentGradeCount(Integer yearPart, Integer quarterNum, Long schoolId, Long subjectsId, Long studentId);

    /**
     * 获取本学期使用课时
     *
     * @param yearPart
     * @param quarterNum
     * @param subjectsId
     * @param schoolId
     * @param studentId
     * @return
     */
    public abstract Long getStudentUseCourseCount(Integer yearPart, Integer quarterNum, Long schoolId, Long subjectsId, Long studentId, Integer lessonType);

    Long getStudentUseCourseCountAllSchool(Integer yearPart,
                                           Integer quarterNum,
                                           Long subjectsId,
                                           Long studentId,
                                           Integer lessonType);

    public abstract List<StudentGrade> getGroupByAtNewList(QueryWrapper queryWrapper);


    boolean updateIsLast(Integer yearPart, Integer quarterNum, Long studentId, Long subjectsId, Integer lessonType);

    /**
     * 在读学员数量
     *
     * @param reMap
     * @return
     */
    public abstract Integer inReadStudentCount(Map reMap, String lessonType);

    /**
     * 异常学员数量
     *
     * @param reMap
     * @return
     */
    public abstract Integer abnormalStudentCount(Map reMap, String lessonType);

    /**
     * 结课学员数量
     *
     * @param reMap
     * @return
     */
    public abstract Integer overStudentCount(Map reMap, String lessonType);

    /**
     * 退费学员数量
     *
     * @param reMap
     * @return
     */
    public abstract Integer returnStudentCount(Map reMap, String lessonType);

    /**
     * 转校学员数量
     *
     * @param reMap
     * @return
     */
    public abstract Integer changeStudentCount(Map reMap, String lessonType);

    /**
     * 停课学员数量
     *
     * @param reMap
     * @return
     */
    public abstract Integer stopStudentCount(Map reMap, String lessonType);

    /**
     * 批量核对
     *
     * @param gradeId
     * @param studentId
     * @return
     */
    public abstract Integer updateIsCheckHouse(String gradeId, String studentId);

    /**
     * 核对人数统计
     *
     * @param yearPart
     * @param quarterNum
     * @param schoolId
     * @param subjectsId
     * @param yearClassId
     * @param courseId
     * @return
     */
    public abstract Long getStudentCheckCount(String yearPart, String quarterNum, String schoolId, String subjectsId, String yearClassId, String courseId, String teacherId, String isCheckHouse, String lessonType,Integer sourseLeve,Long adminId);

    public abstract Long isCheckHouse(Long gradeId, Long studentId);

    /**
     * 获取学生的排课是否有排过（为了判断是否有冲突）
     *
     * @param yearPart
     * @param quarterNum
     * @param weekDates
     * @param timeStart
     * @param timeEnd
     * @param studentStr
     * @return
     */
    public abstract List<ResStudentGradeData> getStudentScheduling(Integer yearPart, Integer quarterNum, String weekDates, String timeStart, String timeEnd, String studentStr, String lessonType);

    StudentGrade getStudentForLast(Integer yearPart, Integer quarterNum, Long subjectsId, Long studentId, Integer lessonType);

    StudentGrade getLastForMaxId(Integer yearPart, Integer quarterNum, Long subjectsId, Long studentId, Integer lessonType);

    void batchUpdateStudentAccount(Integer yearPart, Integer quarterNum, Long subjectsId, Integer lessonType);

    void updateIsPresort(Long schoolId, Long studentId, Integer yearPart, Integer quarterNum, Long subjectsId, Integer lessonType);

    public abstract List<Grade> getGrade(Wrapper wrapper);

    @Async
    void updateOrderDetailId(Integer yearPart, Integer quarterNum, Long schoolId, Long studentId, Long subjectsId, Long orderDetailId);


    @Async
    void updateStudentIsPresort();


    @Async
    void newQuarterUpdateClassType(Integer yearPart, Integer quarterNum, Integer readingStatus, Integer subjectsId);

    Grade getClassTypeNameForStudentId(Integer yearPart,
                                        Integer quarterNum,
                                        Long studentId,
                                        Long subjectsId);

    ResStudentGrade getStudentGradeClassType(Integer yearPart,
                                             Integer quarterNum,
                                             Long subjectsId,
                                             Long studentId,
                                             Integer lessonType);

    IPage<StudentGrade> getStudentGradeLastList(IPage<?> page, Integer yearPart, Integer quarterNum, Long schoolId, Long subjectsId, Long studentId);

    StudentGrade getLastOne(Integer yearPart, Integer quarterNum, Long subjectsId, Long studentId, Integer lessonType);

    void studentClassGradePushMq(Integer yearPart, Integer quarterNum, Long schoolId, Long subjectsId,Long studentId);

    /**
     * 根据班级id调整分班学员班型
     * @param classTypeId
     * @param gradeId
     * @return
     */
    public Boolean updateClassTypeByGradeId(Long classTypeId, Long gradeId);

    boolean addNewStudentGrade(Long orderDetailId, Long schoolId, Integer yearPart, Integer quarterNum, Long studentId, Long subjectsId, Integer yearClassId, Long courseId, Integer surplusCourseNum, Integer lessonType);

    @Async("onlineAsync")
    void autoAllotStudentGrade(Integer yeartPart, Integer quarterNum, Long schoolId, Long subjectsId, Long studentId);

    public abstract Integer useCourseCountByTeacherId(Integer yearPart, Integer quarterNum, Long subjectsId, Long studentId, Long teacherId);

    String getWeekDatesPlanGrade(Integer yearPart,
                                 Integer quarterNum,
                                 Long studentId,
                                 String weekDates
    );

    String getWeekDatesPlanGradeByLessonType(Integer yearPart,
                                             Integer quarterNum,
                                             Long studentId,
                                             String weekDates,
                                             Integer lessonType
    );
}
